<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>员工的添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <input type="hidden" name="keyId" th:value="${param.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>字典名称
            </label>
            <div class="layui-input-inline">
                <input type="text" name="keyNote"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">

            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>字典编码
            </label>
            <div class="layui-input-inline">
                <input type="text" name="keyParm"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">

            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>参数值
            </label>
            <div class="layui-input-inline">
                <input type="number" name="keyValue" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">

            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                增加
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //监听提交
        form.on('submit(add)', function (data) {
            var param = data.field;
            var roleIds = [];
            // 需要单独的获取角色ID的数组
            $("div[class='layui-unselect layui-form-checkbox layui-form-checked']").each(function () {
                var input = $(this).prev();
                roleIds.push(input.val());
            });
            // 添加到param中
            param.roleIds = roleIds;
            $.ajax({
                type: "post",// http请求方法
                url: "/key/add",// 后端的接口
                contentType: 'application/json',
                data: JSON.stringify(param),// 传递到后端的数据
                dataType: "json", // 后端返回的数据类型
                success: function (res) {// 服务器成功响应之后对应的逻辑
                    if (res.code === 200) {
                        layer.alert(res.msg, {icon: 6}, function () {
                            // 重载表格
                            parent.tableIns.reload();
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }
                }
            });

            return false;
        });

    });
</script>

</body>

</html>
